/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-01-22
 * Time: 15:29
 */
public class Test {
    public static int removeDuplicates(int[] nums) {
        //定义一个双指针p与q
        int p = 0;
        int q = 1;
        while (q < nums.length) {
            //判断指针p与指针q所指向的内容是否相同
            if(nums[p] == nums[q]) {
                q++;
            } else {
                nums[p+1] = nums[q];
                p++;
                q++;
            }
        }
        return p+1;
    }
    public static void main(String[] args) {
        int[] arr = {0,0,1,1,1,2,2,3,3,4};
        int ret = removeDuplicates(arr);
        System.out.println(ret);
    }
}
